
# -*- coding: UTF-8 -*-
from urlparse import urlparse
import requests
import urllib
import os
import sys
import time
import threading
import subprocess


# 对[.ts]文件进行排序
def sort_file(_path):
    file_lists = os.listdir(_path)
    file_list = []
    for file_str in filter(lambda file_str: file_str.endswith('.ts'), file_lists):
        file_dict = {}
        file_dict[filter(str.isdigit, file_str)] = file_str
        file_list.append(file_dict)
    file_list.sort(key=sort_fun)
    file_list
    return map(lambda file_dict: file_dict.values()[0], file_list)


def sort_fun(item):
    return item.keys()[0]
# 合并文件


def convert_file(_path, files, filename):
    tmp = []
    for file in files:
        tmp.append(str(file))
    # 合并ts文件
    os.chdir(_path)
    shell_str = ' '.join(tmp)
    shell_str = 'cat ' + shell_str + ' > ' + filename+'.mp4'
    subprocess.call('cat README.md')
    # 删除ts和m3u8文件
    # os.system('del /Q *.ts')
    # os.system('del /Q *.m3u8')


def whileTest():
    count = 1
    while count <= 5:
        time.sleep(1)
        print 'count: %d' % count
        count += 1


class myThread(threading.Thread):
    def __init__(self, threadID, name):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name

    def run(self):
        time.sleep(3)
        print '\n%s' % self.name

# 开启多线程


def generatorThreads():
    global threadList
    threadList = []
    threadCount = 5
    for i in range(threadCount):
        thread = myThread(i, 'thread-'+str(i))
        thread.start()
        threadList.append(thread)


def main():
    # generatorThreads()
    # for thread in threadList:
    #     thread.join()
    # generatorThreads()
    try:

        subprocess.call(['cat','README1.md > dfdf'])
    except OSError:
        print OSError

if __name__ == '__main__':
    # args = sys.argv
    # if len(args) > 2:
    #     main(args[1], args[2])
    main()
